package com.livepan.main;

import com.livepan.server.service.ProblemService;
import com.livepan.server.service.SubmissionService;
import com.livepan.server.service.model.ProblemModel;
import com.livepan.server.service.model.SubmissionModel;
import com.livepan.server.utils.PushJudgerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class MyCommandLineRunner implements CommandLineRunner {
    @Autowired
    private SubmissionService submissionService;

    @Autowired
    private ProblemService problemService;

    private final static boolean isAllRejudge = false;


    @Override
    public void run(String... args) throws Exception {
        List<SubmissionModel> submissionModelList = new ArrayList<>();

//        if (isAllRejudge) {
//            submissionModelList.addAll(submissionService
//                    .querySubmissionList(null, null, null, null, null, 0, 10000));
//        } else {
//            submissionModelList.addAll(submissionService
//                    .querySubmissionList(null, null, null, null, 0, 0, 10000));
//            submissionModelList.addAll(submissionService
//                    .querySubmissionList(null, null, null, null, 1, 0, 10000));
//            submissionModelList.addAll(submissionService
//                    .querySubmissionList(null, null, null, null, 10, 0, 10000));
//        }
//        for (SubmissionModel submissionModel : submissionModelList) {
//            ProblemModel problemModel = problemService.getProblemByID(submissionModel.getProblemId());
//            submissionModel.setContestId(-1);
//            PushJudgerUtil.getInstance().pushJudge(submissionModel, problemModel);
//        }

//        FileReader fr = new FileReader("C:\\Users\\xuanqis\\PycharmProjects\\pythonProject\\apan\\des.txt");
//        BufferedReader br = new BufferedReader(fr);
//        String str;
//        while ((str = br.readLine()) != null) {
//            String[] properties = str.split("livepan");
//            Integer id = Integer.parseInt(properties[0]);
//            String des = properties[1];
//            des = des.replaceAll("\\\\n', '|\\\\u3000|<p>|</p>|<div>|</div>|<hr/>", "");
//
//            String inputDesc = properties[2];
//            inputDesc = inputDesc.replaceAll("\\\\n', '|\\\\u3000|<p>|</p>|<div>|</div>|<hr/>", "");
//
//            String outputDesc = properties[3];
//            outputDesc = outputDesc.replaceAll("\\\\n', '|\\\\u3000|<p>|</p>|<div>|</div>|<hr/>", "");
//
//            String inputSample = properties[4];
//            inputSample = inputSample.replaceAll("\\\\n', '", "\n");
//
//            String outputSample = properties[5];
//            outputSample = outputSample.replaceAll("\\\\n', '", "\n");
//
//            String hint = properties[6];
//
//            hint=hint.replaceAll("\\\\n', '|\\\\u3000|<p>|</p>|<div>|</div>|<hr/>", "");
//
//            String source = properties[7];
//            ProblemModel problemModel = problemService.getProblemByID(id);
//            problemModel.setInputDesc(inputDesc);
//            problemModel.setInputSample(inputSample);
//            problemModel.setOutputDesc(outputDesc);
//            problemModel.setOutputSample(outputSample);
//            problemModel.setHint(hint);
//            problemModel.setSource(source);
//            problemModel.setDescription(des);
//            problemModel = problemService.updateProblem(problemModel);
//            System.out.println(problemModel.getProblemId());
//        }

//        for (int i = 1000; i <= 5000; i++) {
//            ProblemModel problemModel = problemService.getProblemByID(i);
//            if (problemModel != null) {
//                if (problemModel.getTitle() != null) {
//                    problemModel.setTitle(problemModel.getTitle().replace("\\n', '", ""));
//                }
//                problemService.updateProblem(problemModel);
//                System.out.println(problemModel.getProblemId());
//            }
//        }
//        for (int i = 1910; i <= 1985; i++) {
//            Integer id = i + 8390;
//            File file = new File("C:\\Users\\xuanqis\\PycharmProjects\\pythonProject\\apan\\hint\\" + i + ".txt");
//            if (!file.exists()) {
//                continue;
//            }
//            FileReader fr = new FileReader("C:\\Users\\xuanqis\\PycharmProjects\\pythonProject\\apan\\hint\\" + i + ".txt");
//            BufferedReader br = new BufferedReader(fr);
//            String str, result = "";
//            while ((str = br.readLine()) != null) {
//                result = result + str + '\n';
//            }
//            ProblemModel problemModel = problemService.getProblemByID(id);
//            problemModel.setHint(result);
//            problemService.updateProblem(problemModel);
//        }
    }
}
